
    <div class="content margin_top_foot">
        <header class="header fixed_top bg_mx_green"></header>
        <div class="swipe">
            <div class='swipe-wrap'></div>
            <ul class="position"></ul>
        </div>
        <div class="detail"></div>
        <footer class="fixed_bottom flex_justify padding_h_15 border_t_mx bg_white detail_foot">
            <div class="relative iconfont icon-cart font_20 text_center detail_cart" onclick="location.href='<{url route='/shop/cart/index'}>'">
                <div class="badge total detail_total">1</div>
            </div>
            <div class="flex">
                <div class="btn btn_warning detail_addcart" onclick="cart()">加入购物车</div>
                <div class="btn btn_danger gobuy" onclick="gobuy()">立即购买</div>
            </div>
        </footer>
    </div>

    <div class="toast"></div>
    <!-- 轮播模版 -->
    <script type="text/template" charset="utf-8" id='swipe_template'></script>
    <!-- 详情模版 -->
    <script type="text/template" charset="utf-8" id='detail_template'>
        <div class="bg_white padding_10_15 border_b">
            <div class="font_16">{{=it.title}}</div>
            <div class="text_info">{{=it.text}}</div>
            <div class="text_info">库存：{{if(it.total <= 0){}} 产品已售罄 {{}else{}} {{=it.total}} {{}}}</div>
            <div class="flex_justify">
                <div class="warning font_18 lineheight_2">￥{{=it.price}}元/{{=it.unit}}</div>
                <{if empty($goods['pigid']) }>
                <!--<div class="label_mx_green padding_h_5 font_12 circle_5" onclick="location.href='<{url route='/shop/site/from' pigid=$pigno}>'">源头追溯</div>-->
                <{/if}>
            </div>
        </div>
        <div class="bg_white padding_10_15 flex_justify margin_b_10">
            <div class="font_18">购买数量</div>
            <div class="border flex text_center lineheight_3">
                <div class="padding_h_5 bg_grey padding_h_10" onclick="change_num(-1)"><i class="iconfont icon-del"></i></div>
                <div class="border_l padding_h_5 text_center padding_h_15 number">1</div>
                <div class="border_l padding_h_5 bg_grey padding_h_10" onclick="change_num(1)"><i class="iconfont icon-add"></i></div>
            </div>
        </div>
        <div class="bg_white padding_10_15 margin_b_10">{{=it.article}}</div>
        <div class="bg_white">
            <div class="mx_green lineheight_3 border_b padding_h_15"><i class="iconfont icon-xiaoxixuanzhong01 font_20"></i> 顾客评论</div>
            <div class="padding_h_15 border_b">
                {{for(var i=0;i<it.comment.length;i++){}}
                <div class="comment light border_b padding_v_10">
                    <div class="flex_justify margin_b_10">
                        <div class="flex">
                            <div class="width_20">
                                <img class="circle" src="{{=it.comment[i].headimg}}" alt="">
                            </div>
                            <div class="padding_l_10 width_50 text_ellipsis">{{=it.comment[i].name}}</div>
                        </div>
                        <div class="font_16 width_100 grey">
                            {{for(var j=0;j<it.comment[i].star;j++){}}
                                <i class="iconfont icon-star1 warning"></i>
                            {{}}}
                        </div>
                        <div class="font_12 text_ellipsis">{{=it.comment[i].time}}</div>
                    </div>
                    {{if(it.comment[i].picture){}}
                    <div class="flex_row_3 margin_b_10">
                        {{for(var j=0;j<it.comment[i].picture.length;j++){}}
                            <div class="row_one"><img src="{{=it.comment[i].picture[j]}}" alt=""></div>
                        {{}}}
                    </div>
                    {{}}}
                    <div class="">{{=it.comment[i].content}}</div>
                </div>
                {{}}}
            </div>
        </div>
    </script>

    <!-- toast模版 -->
    <script type="text/template" charset="utf-8" id='toast_template'>
        <i class="iconfont icon-toast{{=it.icon}}"></i>
        <div class="toast_text">{{=it.text}}</div>
    </script>
    <script>
            var evalToast = doT.template($("#toast_template").text());
        // 页面初始化
            var banner = <{$banner}>;
            loadswipe(banner)
            var detail = <{$detail}>;console.log(detail)
            var evaldetail = doT.template($("#detail_template").text());
            loaddata(".detail",evaldetail,detail)
            loadheadbar("商品详情");
        // 购物车初始化及操作函数
            var mycarts = get_data("cart")||{},total = 1;
            console.log(mycarts);
            if(mycarts.total){
                $(".total").html(mycarts.total);
            }else{
                $(".total").hide();
            }
            function change_num(i){
                total = parseInt(total) + parseInt(i);
                if(parseInt(total) > detail.nums){
                    total = detail.nums;
                }
                total = total<1?1:total;
                $(".number").html(total);
            }
            function cart(){
                if(detail.nums <= 0){
                    toast("attention","该产品已售罄");
                    return false;
                }
                mycarts = get_data("cart");
                if(mycarts != null && !$.isEmptyObject(mycarts[detail.id]) && mycarts[detail.id].num+total > detail.nums){
                    return false;
                }
                addcart(parseInt(total),{id:detail.id,img:detail.img,o_price:detail.o_price,price:detail.price,title:detail.title,weight:detail.weight,nums:detail.nums})
            }
            function gobuy(){
                set_data({id:detail.id,img:detail.img,o_price:detail.o_price,price:detail.price,title:detail.title,weight:detail.weight,num:total,selected:true},"buy")
                location.href ='/shop/order/confirm?type=gobuy';
            }
    </script>


    <script type="text/javascript" charset="utf-8">
        wx.config(<{$app->wechat->js->config(array('onMenuShareQQ', 'onMenuShareWeibo','onMenuShareTimeline','onMenuShareAppMessage'), false) }>);
        wx.ready(function(){
            wx.onMenuShareTimeline({
                title: "<{$goods['title']}>", // 分享标题
                link: '<{$app->request->getHostInfo()}><{$app->request->url}>', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                imgUrl: "<{$goods['img']}>", // 分享图标
                success: function () {
                    // 用户确认分享后执行的回调函数
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
            wx.onMenuShareAppMessage({
                title: "<{$goods['title']}>", // 分享标题
                desc: "牧心农业邀请您来品尝<{$goods['title']}>", // 分享描述
                link: '<{$app->request->getHostInfo()}><{$app->request->url}>', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                imgUrl: "<{$goods['img']}>", // 分享图标
                type: '', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function () {
                    // 用户确认分享后执行的回调函数
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
            wx.onMenuShareQQ({
                title: "<{$goods['title']}>", // 分享标题
                desc: "牧心农业邀请您来品尝<{$goods['title']}>", // 分享描述
                link: '<{$app->request->getHostInfo()}><{$app->request->url}>', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                imgUrl: "<{$goods['img']}>", // 分享图标
                success: function () {
                    // 用户确认分享后执行的回调函数
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
        })

    </script>
